﻿using System;
using System.IO;
using System.Runtime.Serialization;

namespace _037_自定义协定的名称
{
    class Program
    {
        static void Main(string[] args)
        {

            //将实例进行序列化，并将结果写入文件
            using (FileStream 序列化=File.Open("data.xml",FileMode.Create))
            {
                事前声明类 test = new 事前声明类
                {
                    Space = 5600008210210,
                    Type = 0x0c
                };
                DataContractSerializer 获得 = new DataContractSerializer(test.GetType());
                获得.WriteObject(序列化, test);
            }

            //读取
            using (StreamReader 读操作=new StreamReader("data.xml"))
            {
                Console.Write("序列化后输出的结果：\n");
                Console.Write(读操作.ReadToEnd());
            }

        }
    }

    [DataContract(Name ="disk_info")]
    public class 事前声明类
    {
        [DataMember(Name ="total_space")]
        public long Space { get; set; }
        [DataMember(Name ="diver_type")]
        public byte Type { get; set; }
    }
}
